<template>
	<view>
		<view class="meituan-logo">
			<image src="/static/meituan_logo.png"></image>
			<view>美团自助验券</view>
		</view>
		<view class="yt-list">
			<view class="yt-list-cell desc-cell" @click="toSelectStore()">
				<input class="desc" type="text" v-model="store.name" disabled="" placeholder="请选择兑换的店铺"
					placeholder-class="placeholder" />
			</view>
			<view class="yt-list-cell desc-cell" style="margin-top: 50rpx;margin-bottom: 30rpx;">
				<input class="desc" type="text" v-model="meituanNum" placeholder="点击输入兑换码"
					placeholder-class="placeholder" />
				<image :src="saomaImg" style="width: 50rpx;height: 50rpx;" @click="scanCode"></image>
			</view>
		</view>
		<view class="hexiao-tip">
			<view class="tip-header">温馨提示</view>
			<view class="tip-content">1、自助核销验券之前请确认所选的门店是否正确</view>
			<view class="tip-content">2、抖音验券请到抖音APP的订单详情页复制券码然后进行自助核销验券</view>
			<view class="tip-content">3、核销成功之后会给自己的充值对应的积分，下单时使用积分下单即可</view>
		</view>
		<!-- 底部 -->
		<view class="footer">
			<text class="submit" @click="duihuan">兑换</text>
		</view>
	</view>
</template>

<script>
	import Api from '@/common/api';
	import {
		mapState
	} from 'vuex';
	export default {
		components: {},
		data() {
			return {
				meituanNum: '',
				stores: [],
				index: 0,
				store: null,
				meituanStoreId: '',
				saomaImg: '/static/saoma.png',
				noClick:true
			};
		},
		onLoad(options) {
			let that = this;
		},
		onShow() {
			let that = this;
			uni.$on('store', function(data) {
				that.store = data
			})
			if (null != that.store) {
				this.getStoreById(that.store.id)
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			scanCode() {
				let that = this;
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						// that.convert(res.result);
						that.meituanNum = res.result;
					}
				})
			},
			toSelectStore() {
				uni.navigateTo({
					url: '/pages/store/storeList?type=duihuan'
				})
			},
			selectStore: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value;
			},
			async getAllStores(){
				let that = this;
				let params = {};
				let allStores = await Api.apiCall('get', Api.qsg.getAllStore, params);
				console.log(JSON.stringify(allStores));
				if(allStores){
					that.stores = allStores;
				}
			},
			async duihuan() {
				let that = this;
				if(that.noClick){
					that.noClick = false;
					setTimeout(()=> {
						that.noClick= true;
					}, 5000)
				}else{
					uni.showToast({
						icon:'loading',
						title:'请勿重复点击'
					})
					return false;
				}
				if(that.store==null){
					uni.showModal({
						title: '提示',
						content: '请选择需要兑换的店铺',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							}
						}
					});
					return false;
				}
				if(that.meituanNum==''){
					uni.showModal({
						title: '提示',
						content: '兑换码不能为空',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							}
						}
					});
					return false;
				}
				
				let meituanStoreId = that.meituanStoreId;
				if (meituanStoreId == '') {
					uni.showModal({
						title: '提示',
						content: '该店暂不支持美团自动核销',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							}
						}
					});
					return false;
				}
				console.log("美团店铺ID=" + meituanStoreId);
				let params = {
					meituanNum: that.meituanNum,
					meituanStoreId: meituanStoreId,
				};
				let data = await Api.apiCall('post', Api.order.duiHuan, params);
				console.log(data);
				if(data){
					uni.showModal({
						title: '提示',
						content: '兑换成功,快使用积分去下单吧',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url:'/pages/meallist/selectRoom?storeId='+that.store.id
								})
							}
						}
					});
				}
			},
			async getStoreById() {
				let data = await Api.apiCall('get', Api.store.getStoreById, {
					storeId: this.store.id
				});
				if (data) {
					console.log(data)
					this.meituanStoreId = data.openShopUuid;
				}
			}
		}
	};
</script>

<style lang="scss">
	
	.meituan-logo{
		margin-top: 100rpx;
		margin-bottom: 40rpx;
		text-align: center;
		
		image{
			width: 150rpx;
			height: 150rpx;
			border-radius: 30%;
		}
	}

	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28upx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34upx;
			margin-right: 24upx;
		}

		.address {
			margin-top: 16upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

	.goods-section {
		margin-top: 16upx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50upx;
			height: 50upx;
			border-radius: 100px;
		}

		.name {
			font-size: 30upx;
			color: $font-color-base;
			margin-left: 24upx;
		}

		.g-item {
			display: flex;
			margin: 20upx 30upx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}

			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
			}

			.title {
				font-size: 30upx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26upx;
				color: $font-color-light;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 32upx;
				color: $font-color-dark;
				padding-top: 10upx;

				.price {
					margin-bottom: 4upx;
				}

				.number {
					font-size: 26upx;
					color: $font-color-base;
					margin-left: 20upx;
				}
			}

			.step-box {
				position: relative;
			}
		}
	}

	.yt-list {
		width: 750upx;
		height: auto;
		padding: 30upx;
		box-sizing: border-box;
		border-radius: 10rpx;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx;
		line-height: 70upx;
		position: relative;
		background: #f9f9f9;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 32upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}
		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-light;
			margin-right: 10upx;
			color: #333333;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}

			&.red {
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90upx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

	/* 支付列表 */
	.pay-list {
		padding-left: 40upx;
		margin-top: 16upx;
		background: #fff;

		.pay-item {
			display: flex;
			align-items: center;
			padding-right: 20upx;
			line-height: 1;
			height: 110upx;
			position: relative;
		}

		.icon-weixinzhifu {
			width: 80upx;
			font-size: 40upx;
			color: #6bcc03;
		}

		.icon-alipay {
			width: 80upx;
			font-size: 40upx;
			color: #06b4fd;
		}

		.icon-xuanzhong2 {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 40upx;
			color: $base-color;
		}

		.tit {
			font-size: 32upx;
			color: $font-color-dark;
			flex: 1;
		}
	}

	.footer {
		width: 650rpx;
		height: 90upx;
		font-size: 30upx;
		margin:auto;
		.submit {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 100%;
			color: #fbc202;
			font-size: 32upx;
			font-weight: 600;
			background-color: #000002;
			letter-spacing: 10rpx;
		}
	}

	/* 优惠券面板 */
	.mask {
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 9995;
		transition: 0.3s;

		.mask-content {
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: 0.3s;
			overflow-y: scroll;
		}

		&.none {
			display: none;
		}

		&.show {
			background: rgba(0, 0, 0, 0.4);

			.mask-content {
				transform: translateY(0);
			}
		}
	}

	/* 优惠券列表 */
	.coupon-item {
		display: flex;
		flex-direction: column;
		margin: 20upx 24upx;
		background: #fff;

		.con {
			display: flex;
			align-items: center;
			position: relative;
			height: 120upx;
			padding: 0 30upx;

			&:after {
				position: absolute;
				left: 0;
				bottom: 0;
				content: '';
				width: 100%;
				height: 0;
				border-bottom: 1px dashed #f3f3f3;
				transform: scaleY(50%);
			}
		}

		.left {
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			overflow: hidden;
			height: 100upx;
		}

		.title {
			font-size: 32upx;
			color: $font-color-dark;
			margin-bottom: 10upx;
		}

		.time {
			font-size: 24upx;
			color: $font-color-light;
		}

		.right {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			color: $font-color-base;
			height: 100upx;
		}

		.price {
			font-size: 44upx;
			color: $base-color;

			&:before {
				content: '￥';
				font-size: 34upx;
			}
		}

		.tips {
			font-size: 24upx;
			color: $font-color-light;
			line-height: 60upx;
			padding-left: 30upx;
		}

		.circle {
			position: absolute;
			left: -6upx;
			bottom: -10upx;
			z-index: 10;
			width: 20upx;
			height: 20upx;
			background: #f3f3f3;
			border-radius: 100px;

			&.r {
				left: auto;
				right: -6upx;
			}
		}
	}
	.hexiao-tip{
		background-color: #f9f9f9;
		height: 200rpx;
		margin-left: 20rpx;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		padding: 10rpx;
	    
		.tip-header{
			font-weight: bold;
		}
		
		.tip-content{
			font-size: 20rpx;
			color: #9A9A9A;
		}
	}
</style>
